package ee.tallink.common.service;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import ee.tallink.common.ServiceException;
import ee.tallink.common.db.DataBase;

@Provider
public class ServiceExceptionMapper implements ExceptionMapper<ServiceException> {
	public Response toResponse(ServiceException exception) {
		if( DataBase.isOpen() ) DataBase.close();
		return RestService.buildErrorResponse(exception);
	}
}
